/**
 * @Description 评价Dao
 * @author 20155872 游宇
 * @create 2018-05-10 9:12
 **/

package com.campus_information_portal.dao;
import com.campus_information_portal.entity.Remark;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @className RemarkDao
 * @Description 评价Dao
 * @author 20155872 游宇
 * @create 2018-05-10 9:12
 **/
public interface RemarkDao {

   /**
    * @Description: 根据学期和学生id 来查询某学生某学期的评教记录
    * @author: 20155872 游宇
    * @methodName: searchRemarks
    * @param:  int stu_info_id, int term_id
    * @returnType: List<Remark>
    * @createTime: 2018/5/14 18:07
    **/
    @Select("select * from remark where stu_info_id=#{stu_info_id} and term_id=#{term_id}")
    List<Remark> searchRemarks(@Param("stu_info_id") int stu_info_id, @Param("term_id") int term_id);

    /**
     * @Description: 插入一条评价记录
     * @author: 20155872 游宇
     * @methodName: addremark
     * @param: Remark remark
     * @returnType: boolean
     * @createTime: 2018/5/14 18:07
     **/
    @Insert("insert into remark(stu_info_id,te_info_id,course_id,term_id,mark_one,mark_two,mark_three," +
            "mark_four,mark_five,mark_six,mark_seven,mark_eight,mark_nine,mark_ten,remark_createtime)" +
            "values(#{stuInfoId},#{teInfoId},#{courseId},#{termId}," +
            "#{markOne},#{markTwo},#{markThree},#{markFour},#{markFive}," +
            "#{markSix},#{markSeven},#{markEight},#{markNine},#{markTen},#{remarkCreatetime})")
    boolean addRemark(Remark remark);

    /**
     * @Description: 根据remarkid来更新remark记录
     * @author: 20155872 游宇
     * @methodName: updateRemark
     * @param: Remark remark
     * @returnType: boolean
     * @createTime: 2018/5/15 16:21
     **/
    @Update("update remark set mark_one=#{markOne},mark_two=#{markTwo},mark_three=#{markThree},mark_four=#{markFour}," +
            "mark_five=#{markFive},mark_six=#{markSix},mark_seven=#{markSeven},mark_eight=#{markEight}," +
            "mark_nine=#{mark_nine},mark_ten=#{markTen} where remark_id=#{remarkId}")
    boolean updateRemark(Remark remark);

    /**
     * @Description: 根据remarkId 删除一条remark记录
     * @author: 20155872 游宇
     * @methodName: deleteByRemarkId
     * @param: int remarkId
     * @returnType: boolean
     * @createTime: 2018/5/15 16:55
     **/
    @Delete("delete from remark where remark_id=#{remarkId}")
    boolean deleteByRemarkId(@Param("remarkId") int remarkId);


    /**
     * @Description: 根据教师信息id和学期id来查询某个教师某个学期问题9 的所有建议
     * @author: 20155872 游宇
     * @methodName: getAllQuestionNineByteInfoIdAndterm
     * @param:  int teInfoId, int termId
     * @returnType: List<String>
     * @createTime: 2018/5/17 9:03
     **/
    @Select("select mark_nine from remark where te_info_id=#{teInfoId} and term_id=#{termId}")
    List<String> getAllMarkNineByteInfoIdAndterm(@Param("teInfoId")int teInfoId,@Param("termId")int termId);

 /**
  * @Description: 根据教师信息id和学期id来查询某个教师某个学期问题10 的所有建议
  * @author: 20155872 游宇
  * @methodName: getAllQuestionNineByteInfoIdAndterm
  * @param:  int teInfoId, int termId
  * @returnType: List<String>
  * @createTime: 2018/5/17 9:03
  **/
 @Select("select mark_ten from remark where te_info_id=#{teInfoId} and term_id=#{termId}")
 List<String> getAllMarkTenByteInfoIdAndterm(@Param("teInfoId")int teInfoId,@Param("termId")int termId);



 /**
  * @Description: 查询某个学期、某个老师的平均得分
  * @author: 20155872 游宇
  * @methodName: getAvgGrade
  * @param: int termId,int teInfoId
  * @returnType: BigDecimal
  * @createTime: 2018/5/17 11:18
  **/
@Select("SELECT AVG(mark_one+mark_two+mark_three+mark_four+mark_five+mark_six+mark_seven+mark_eight) AS '平均分'\n" +
        "FROM remark where term_id=#{termId} and te_info_id=#{teInfoId};")
public BigDecimal getAvgGrade(@Param("termId") int termId,@Param("teInfoId")int teInfoId);





}
